//
// Unihan Input Method
//
// Copyright © 2002-2007 Sun Wah Linux Ltd.
//
//
// This library is free software; you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as
// published by the Free Software Foundation; either version 2.1 of the
// License, or (at your option) any later version.
//
// This library is distributed in the hope that it will be useful, but
// WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public
// License along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
// USA
//
// $Id: prefedit.c 796 2007-06-30 19:00:01Z roger $
//

/*
** $Id: prefedit.c 796 2007-06-30 19:00:01Z roger $
**
** Unihan Chinese Platform
** Unihan Preference utility for GNOME2
*/

#ifdef HAVE_CONFIG_H
#  include <config.h>
#endif /* HAVE_CONFIG_H */

#include <langinfo.h>
#include <gnome.h>
#include <gconf/gconf-client.h>
#include <unihan_im_keycodes.h>
#include <gtk/gtk.h>
#include <unihan-gconf.h>

#include "prefedit.h"
#include "Prefedit_cb.h"
#include "list_ctrl.h"
#include "list_factory.h"

static void init_gconf_stuff(GladeXML *);
static void get_current_settings(GladeXML *);
static void in_tray_changed(GConfClient *, guint, GConfEntry *, gpointer);
static void default_im_changed(GConfClient *, guint, GConfEntry *, gpointer);
static void im_option_changed(GConfClient *client, guint cnxn_id, GConfEntry *entry, gpointer data);
static void font_changed(GConfClient *, guint, GConfEntry *, gpointer);
static void phrase_mode_changed(GConfClient *, guint, GConfEntry *, gpointer);
static void use_gsuggest_changed(GConfClient *, guint, GConfEntry *, gpointer);
static void update_tcsc_radiobutton(int, GladeXML *);
static void update_in_tray_radiobutton(gboolean, GladeXML *);
static void update_hz_radiobutton(gboolean, GladeXML *);
static void update_default_im_optionmenu(const gchar *, GladeXML *);
static void update_phrase_mode_checkbutton(gboolean, GladeXML *);
static void update_use_gsuggest_checkbutton(gboolean, GladeXML *);
static void show_locale_warning(char *, GladeXML *);
static void hide_locale_warning(GladeXML *);
static void set_window_icon(void);
static gboolean look_for_im_list(gpointer);
static void retrieved_im_list_selection(GtkClipboard *, GtkSelectionData *, gpointer);

/* common global */
GList *im_all_list = NULL;
GList *im_curr_list = NULL;
GList *symbol_list = NULL;
GList *symbol_list_new = NULL;
GList *word_list = NULL;
GList *word_list_new = NULL;
GtkClipboard *clip_status = NULL;
GtkClipboard *clip_prefedit = NULL;
static guint timeout_handler_id;
GtkListStore *im_all_list_store = NULL;
GtkListStore *im_curr_list_store = NULL;
/* common end */

/* IM global */
gchar curr_im_id[50];
/* IM end */

/* prefedit global */
GladeXML *xml_prefedit = NULL;
GladeXML *xml_IMAdd = NULL;
GladeXML *xml_SymbolNew = NULL;
GladeXML *xml_WordNew = NULL;
GladeXML *xml_upimdpref = NULL;
GladeXML *xml_itabcpref = NULL;
GladeXML *xml_pinyinpref = NULL;
GladeXML *xml_wubipref = NULL;
/* prefedit end */

/* UserDefPunc global */
gchar *sym_sel = NULL;
gchar *key_sel = NULL;
/* UserDefPunc end */


static void
init_gconf_stuff(GladeXML *xml)
{
	GConfClient *client = gconf_client_get_default();
	
	/* Register gconf callbacks */
	gconf_client_add_dir(client, UNIHAN_ROOT_KEY,
			     GCONF_CLIENT_PRELOAD_NONE, NULL);
	gconf_client_notify_add(client, PREEDIT_FONT_KEY,
			        font_changed, xml, NULL, NULL);
	gconf_client_notify_add(client, CANDIDATE_FONT_KEY,
			        font_changed, xml, NULL, NULL);
	gconf_client_notify_add(client, NUMBER_FONT_KEY,
			        font_changed, xml, NULL, NULL);
	gconf_client_notify_add(client, STATUS_FONT_KEY,
			        font_changed, xml, NULL, NULL);
	gconf_client_notify_add(client, DEFAULT_IM_KEY,
				default_im_changed, xml, NULL, NULL);
	gconf_client_notify_add(client, STATUS_IN_TRAY_KEY,
				in_tray_changed, xml, NULL, NULL);
	gconf_client_notify_add(client, PHRASE_MODE_KEY,
				phrase_mode_changed, xml, NULL, NULL);
	gconf_client_notify_add(client, USE_GOOGLE_SUGGEST_KEY,
				use_gsuggest_changed, xml, NULL, NULL);
    gconf_client_notify_add(client, UNIHAN_ROOT_KEY "/im-options",
                im_option_changed, xml, NULL, NULL);
}

static void
update_tcsc_radiobutton(int tc_sc_mode, GladeXML *xml)
{
	GtkWidget *w = glade_xml_get_widget(xml, "TCSCOptionMenu");
	gtk_option_menu_set_history(w, tc_sc_mode);
}

static void
update_in_tray_radiobutton(gboolean in_tray, GladeXML *xml)
{
        gchar *in_tray_button;
        if (in_tray) {
                in_tray_button = "inTrayRadio";
        } else {
                in_tray_button = "notInTrayRadio";
        }
        GtkWidget *w = glade_xml_get_widget(xml, in_tray_button);
        gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(w), TRUE);
}

static void
update_hz_radiobutton(gboolean candidate_horizontally, GladeXML *xml)
{
        gchar *hz_button;
        if (candidate_horizontally) {
                hz_button = "hzRadio";
        } else {
                hz_button = "vtRadio";
        }
        GtkWidget *w = glade_xml_get_widget(xml, hz_button);
        gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(w), TRUE);
}

static void
update_default_im_optionmenu(const gchar *default_im, GladeXML *xml)
{
	GtkWidget *w;
	int default_im_idx = 0;
	GList *im_list_ = im_curr_list;

	if (!im_list_) return;
	while (im_list_) {
		IMInfo *inf = (IMInfo *)im_list_->data;
		if (!strcmp(inf->id, default_im))
			break;
		++default_im_idx;
		im_list_ = g_list_next(im_list_);
	}
	if (!im_list_)
		default_im_idx = 0;
	w = glade_xml_get_widget(xml_prefedit, "defaultIMOption");
	gtk_combo_box_set_active(GTK_COMBO_BOX(w), default_im_idx);
        // FIXME:combobox
}

static void
update_im_option(const gchar *option, gboolean value, GladeXML *xml)
{
        GtkWidget *w;

        w = glade_xml_get_widget(xml, option);
        if (w)
                gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(w), value);
}

static void
update_phrase_mode_checkbutton(gboolean phrase_mode, GladeXML *xml)
{
        GtkWidget *w = glade_xml_get_widget(xml, "phraseCheck");
        gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(w), phrase_mode);

        w = glade_xml_get_widget(xml, "gsuggestCheck");
        gtk_widget_set_sensitive(w, phrase_mode);
}

static void
update_use_gsuggest_checkbutton(gboolean use_gsuggest, GladeXML *xml)
{
        GtkWidget *w = glade_xml_get_widget(xml, "gsuggestCheck");
        gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(w), use_gsuggest);
}

#if 0
static GdkPixbuf *
get_stock_icon_scaled(GtkWidget *wg, const gchar *stock_id)
{
	GdkPixbuf *icon, *scaled;
	gint w, h;
	
	icon = gtk_widget_render_icon(wg, stock_id, GTK_ICON_SIZE_DIALOG, NULL);
	gtk_icon_size_lookup(GTK_ICON_SIZE_MENU, &w, &h);
	scaled = gdk_pixbuf_scale_simple(icon, w, h, GDK_INTERP_BILINEAR);
	g_object_unref(G_OBJECT(icon));
	return scaled;
}
#endif

static void
show_locale_warning(char *encoding, GladeXML *xml)
{
	GtkWidget *w = glade_xml_get_widget(xml, "localeWarnLabel");
	const gchar *text;
        gchar *newtext;
	gboolean is_big5 = (encoding[0] == 'G' || encoding[0] == 'g') ? FALSE : TRUE;
	gchar *from, *to;

	if (is_big5) {
		from = _("simplified");
		to = _("traditional");
	} else {
		from = _("traditional");
		to = _("simplified");
	}

	text = gtk_label_get_text(GTK_LABEL(w));
	newtext = g_strdup_printf(text, from, to,  _(encoding), from);
	gtk_label_set_text(GTK_LABEL(w), newtext);
	g_free(newtext);

	gtk_widget_show(w);

        w = glade_xml_get_widget(xml, "localeWarn");
        gtk_widget_show(w);

	w = glade_xml_get_widget(xml, "noConvRadio");
	gtk_widget_set_sensitive(w, FALSE);
	w = glade_xml_get_widget(xml, "tc2scRadio");
	gtk_widget_set_sensitive(w, FALSE);
	w = glade_xml_get_widget(xml, "sc2tcRadio");
	gtk_widget_set_sensitive(w, FALSE);
}

static void
hide_locale_warning(GladeXML *xml)
{
	GtkWidget *w = glade_xml_get_widget(xml, "localeWarn");
	//gtk_widget_hide(w);
}


void
refresh_im_default(void)
{
	GConfClient *client = gconf_client_get_default();
	const gchar *im_curr_default = gconf_client_get_string(client, DEFAULT_IM_KEY, NULL);
	IMInfo *info = NULL;
	GList *im = im_curr_list;
	GtkWidget *w = NULL;

	//gconf_client_set_string(client, DEFAULT_IM_KEY, DEFAULT_IM_ZERO, NULL);

	/*if (im_curr_list_store)
		gtk_list_store_clear(im_curr_list_store); // core dump while clear*/

        im_curr_list_store = list_store_new_from_im_list(im_curr_list);
        
	w = glade_xml_get_widget(xml_prefedit, "defaultIMOption");
	IM_default_create_menu_by_store(GTK_COMBO_BOX(w), im_curr_list_store);

	while (im) {
		info = (IMInfo *)im->data;
		if (g_ascii_strcasecmp(info->id, im_curr_default) == 0)
			break;
		im = g_list_next(im);
	}

	if (!im) {
		im = im_curr_list;
		info = (IMInfo *)im->data;
		gconf_client_set_string(client, DEFAULT_IM_KEY, info->id, NULL);
	}
}

static void
get_current_settings(GladeXML *xml)
{
	GConfClient *client = gconf_client_get_default();
	gint tc_sc_mode = 0;
    gboolean in_tray = TRUE;
    gboolean phrase_mode = TRUE;
    gboolean use_gsuggest = TRUE;
	gboolean candidate_horizontally = TRUE;
	char *codeset;
	gchar *fontstr = NULL, *colorstr = NULL;
	GdkColor color;
	GtkWidget *w;
	
	tc_sc_mode = gconf_client_get_int(client, TC_SC_KEY, NULL);
	update_tcsc_radiobutton(tc_sc_mode, xml);
	codeset = nl_langinfo(CODESET);
	if ((strcmp(codeset, "UTF-8") != 0) 
	    && (strcmp(codeset, "GB18030") != 0)) {
		// oops, we're not in an UTF-8 locale
		show_locale_warning(codeset, xml);
	} else {
		hide_locale_warning(xml);
	}

        in_tray = gconf_client_get_bool(client, STATUS_IN_TRAY_KEY, NULL);
        update_in_tray_radiobutton(in_tray, xml);

		candidate_horizontally = gconf_client_get_bool(client, CANDIDATE_HORIZONTALLY_KEY, NULL);
		update_hz_radiobutton(candidate_horizontally, xml);
	
	phrase_mode = gconf_client_get_bool(client, PHRASE_MODE_KEY, NULL);
	update_phrase_mode_checkbutton(phrase_mode, xml);

    use_gsuggest = gconf_client_get_bool(client, USE_GOOGLE_SUGGEST_KEY, NULL);
    update_use_gsuggest_checkbutton(use_gsuggest, xml);

	fontstr = gconf_client_get_string(client, PREEDIT_FONT_KEY, NULL);
	w = glade_xml_get_widget(xml, "fontPicker");
	gtk_font_button_set_font_name(GTK_FONT_BUTTON(w), fontstr);
	g_free(fontstr);
	
	colorstr = gconf_client_get_string(client, PREEDIT_FG_KEY, NULL);
	if (!colorstr || !gdk_color_parse(colorstr, &color)) {
		gdk_color_parse("#000000", &color);
	}
	w = glade_xml_get_widget(xml, "fgColorPicker");
	gtk_color_button_set_color(GTK_COLOR_BUTTON(w), &color);
	g_free(colorstr);

	colorstr = gconf_client_get_string(client, PREEDIT_BG_KEY, NULL);
	if (!colorstr || !gdk_color_parse(colorstr, &color)) {
		gdk_color_parse("#FFFFFF", &color);
	}
	w = glade_xml_get_widget(xml, "bgColorPicker");
	gtk_color_button_set_color(GTK_COLOR_BUTTON(w), &color);
	g_free(colorstr);

	
}

static void
default_im_changed(GConfClient *client, guint cnxn_id, GConfEntry *entry, gpointer data)
{
	GladeXML *xml = (GladeXML*)data;
	const gchar *default_im = NULL;
	GConfValue *value = gconf_entry_get_value(entry);
	if (value != NULL) {
		default_im = gconf_value_get_string(value);
		update_default_im_optionmenu(default_im, xml);
	}
}

static void
in_tray_changed(GConfClient *client, guint cnxn_id, GConfEntry *entry, gpointer data)
{
        GladeXML *xml = (GladeXML *)data;
        gboolean in_tray = TRUE;
        GConfValue *value = gconf_entry_get_value(entry);
        if (value != NULL) {
                in_tray = gconf_value_get_bool(value);
                update_in_tray_radiobutton(in_tray, xml);
        }
}

static void
font_changed(GConfClient *client, guint cnxn_id, GConfEntry *entry, gpointer data)
{
	GladeXML *xml = (GladeXML*)data;
	GtkWidget *w;

	w = glade_xml_get_widget(xml, "componentOption");
	on_componentOption_selected(GTK_MENU_SHELL(GTK_OPTION_MENU(w)->menu), xml);
}

static void
im_option_changed(GConfClient *client, guint cnxn_id, GConfEntry *entry, gpointer data)
{
        GladeXML *xml = (GladeXML *)data;
        GConfValue *value = gconf_entry_get_value(entry);
        if (value != NULL) {
                const gchar *entryKey = gconf_entry_get_key(entry);
                const gchar *imOpt = entryKey + strlen(UNIHAN_ROOT_KEY "/im-options/");
                update_im_option(imOpt, gconf_value_get_bool(value), xml);
        }
}

static void
phrase_mode_changed(GConfClient *client, guint cnxn_id, GConfEntry *entry, gpointer data)
{
    GladeXML *xml = (GladeXML *)data;
    GConfValue *value = gconf_entry_get_value(entry);
    if (value != NULL) {
        gboolean phrase_mode = gconf_value_get_bool(value);
        update_phrase_mode_checkbutton(phrase_mode, xml);
    }
}

static void
use_gsuggest_changed(GConfClient *client, guint cnxn_id, GConfEntry *entry, gpointer data)
{
    GladeXML *xml = (GladeXML *)data;
    gboolean use_gsuggest = TRUE;
    GConfValue *value = gconf_entry_get_value(entry);
    if (value != NULL) {
        use_gsuggest = gconf_value_get_bool(value);
        update_use_gsuggest_checkbutton(use_gsuggest, xml);
    }
}

static void
set_window_icon(void)
{
	GdkPixbuf *pixbuf = NULL;
	GList *iconlist = NULL;
	
	pixbuf = gdk_pixbuf_new_from_file(UNIHAN_DATA_DIR "/images/icon.png", NULL);
	if (!pixbuf)
		return;
	iconlist = g_list_append(iconlist, pixbuf);
	gtk_window_set_default_icon_list(iconlist);
	g_list_free(iconlist);
	g_object_unref(G_OBJECT(pixbuf));
}

static void
retrieved_im_list_selection(GtkClipboard *cb, GtkSelectionData *seldata, gpointer data)
{
	int num_im;
	
	if (!seldata) return;
	if (seldata->length < 0) return;
	num_im = atoi((char *)seldata->data);
	if (num_im < 1) return;

	im_curr_list = IM_retrieve_list((gchar *)seldata->data);
	gtk_timeout_remove(timeout_handler_id);
}

static gboolean
look_for_im_list(gpointer data)
{
	gtk_clipboard_request_contents(clip_status,
			gdk_atom_intern("_IM_ALL_LIST", FALSE),
			retrieved_im_list_selection, data);
	return TRUE;
}

int
main(int argc, char *argv[])
{
	GError *err = NULL;
	GConfClient *client;
	GtkWidget *w;
	GtkTreeSelection *selection;
	GtkTreeModel *model;
	GtkTreeIter iter;
	gchar *id = NULL;

	gtk_set_locale();

	/* i18n stuff */
	bind_textdomain_codeset(GETTEXT_PACKAGE, "UTF-8");
	bindtextdomain(GETTEXT_PACKAGE, GNOMELOCALEDIR);
	textdomain(GETTEXT_PACKAGE);
	
	//gtk_init(&argc, &argv);
	gnome_program_init (PACKAGE, VERSION,
				      	LIBGNOMEUI_MODULE, argc, argv,
				    	GNOME_PARAM_APP_DATADIR, PREFEDIT_DATA_DIR,
				    	GNOME_PARAM_NONE);
	
	glade_init();
	if (!gconf_init(argc, argv, &err)) {
		g_error("Failed to init GConf: %s", err->message);
		g_error_free(err);
		exit(1);
	}
	client = gconf_client_get_default();
	if (!gconf_client_get_bool(client, CHECK_MODULE_INFO_KEY, NULL)) {
		gconf_client_set_bool(client, CHECK_MODULE_INFO_KEY, TRUE, NULL);
	} else {
		gconf_client_set_bool(client, CHECK_MODULE_INFO_KEY, FALSE, NULL);
	}

	set_window_icon();

	xml_prefedit = glade_xml_new(UNIHAN_DATA_DIR "/xml/prefedit.glade",
			"mainWindow", NULL);
	glade_xml_signal_autoconnect(xml_prefedit);

	init_gconf_stuff(xml_prefedit);

	clip_status = gtk_clipboard_get(gdk_atom_intern("_UNIHAN_STATUS",
				FALSE));

	clip_prefedit = gtk_clipboard_get(gdk_atom_intern("_UNIHAN_PREFEDIT",
				FALSE));
	{
		GtkTargetEntry targets[2] = {
			{ "_SYMBOL_LIST", 0, TARGET_SYMBOL_LIST },
			{ "_WORD_LIST", 0, TARGET_WORD_LIST }
		};
		gtk_clipboard_set_with_data(clip_prefedit, targets, 2,
				clipboard_get_handler, NULL, NULL);
	}

	if ((im_curr_list = IM_get_curr_list()) == NULL) {
		GtkWidget *w;
                w = glade_xml_get_widget(xml_prefedit, "noIMListWarn");
                gtk_widget_show(w);

		// look for the IM list every 5 seconds
		timeout_handler_id = gtk_timeout_add(5000,
				look_for_im_list, xml_prefedit);
	}
        im_curr_list_store = list_store_new_from_im_list(im_curr_list);

	w = glade_xml_get_widget(xml_prefedit, "defaultIMOption");
	IM_default_create_menu_by_store(GTK_COMBO_BOX(w), im_curr_list_store);
	g_signal_connect(GTK_COMBO_BOX(w),
			"changed",
                        G_CALLBACK(on_defaultIMOption_selected),
			xml_prefedit);

	im_all_list = IM_get_all_list();
	symbol_list = Symbol_get_list();
	word_list = Word_get_list();

	get_current_settings(xml_prefedit);
	glade_xml_signal_connect(xml_prefedit, "gtk_main_quit",
			G_CALLBACK(gtk_main_quit));

	w = glade_xml_get_widget(xml_prefedit, "treeviewIM");
	IM_treeview_add_column(GTK_TREE_VIEW(w));
	IM_refresh_treeview_by_im_list(GTK_TREE_VIEW(w), im_curr_list);
	selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(w));
	gtk_tree_selection_set_mode(selection, GTK_SELECTION_SINGLE);
	model = gtk_tree_view_get_model(GTK_TREE_VIEW(w));
	if(gtk_tree_model_get_iter_first(model, &iter))
		gtk_tree_selection_select_iter(selection, &iter);

	w = glade_xml_get_widget(xml_prefedit, "buttonIMProperty");
	if (gtk_tree_selection_get_selected(selection, &model, &iter)) {
		gtk_tree_model_get(model, &iter,
				STORE_2, &id,
				-1);
		g_stpcpy(curr_im_id, id);
		if(!strcmp(curr_im_id,"upim") || 
		   !strcmp(curr_im_id,"itabc") || 
		   //!strcmp(curr_im_id,"pinyin") || 
		   !strcmp(curr_im_id,"wubizixing"))
		{
			gtk_widget_set_sensitive(GTK_WIDGET(w),TRUE);
		}else{
			gtk_widget_set_sensitive(GTK_WIDGET(w),FALSE);
		}
	}

	g_signal_connect(GTK_TREE_SELECTION(selection),
			"changed",
			G_CALLBACK(on_IM_Tree_View_Selection_changed),
			NULL);

	
	w = glade_xml_get_widget(xml_prefedit, "treeviewSymbol");
	Symbol_treeview_add_column(GTK_TREE_VIEW(w));
	Symbol_refresh_treeview_by_symbol_list(GTK_TREE_VIEW(w), symbol_list);
	selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(w));
	gtk_tree_selection_set_mode(selection, GTK_SELECTION_SINGLE);
	g_signal_connect(GTK_TREE_SELECTION(selection),
			"changed",
			G_CALLBACK(on_Symbol_Tree_View_Selection_changed),
			NULL);

	w = glade_xml_get_widget(xml_prefedit, "treeviewWord");
	Word_treeview_add_column(GTK_TREE_VIEW(w));
	Word_refresh_treeview_by_word_list(GTK_TREE_VIEW(w), word_list);
	selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(w));
	gtk_tree_selection_set_mode(selection, GTK_SELECTION_SINGLE);
	g_signal_connect(GTK_TREE_SELECTION(selection),
			"changed",
			G_CALLBACK(on_Word_Tree_View_Selection_changed),
			NULL);
	
	w = glade_xml_get_widget(xml_prefedit, "buttonIMAdd");
	g_signal_connect(GTK_OBJECT(w),
			"clicked",
			G_CALLBACK(on_IM_Button_Add_clicked),
			NULL);

	w = glade_xml_get_widget(xml_prefedit, "buttonIMRemove");
	g_signal_connect(GTK_OBJECT(w),
			"clicked",
			G_CALLBACK(on_IM_Button_Remove_clicked),
			NULL);

	w = glade_xml_get_widget(xml_prefedit, "buttonIMProperty");
	g_signal_connect(GTK_WIDGET(w),
			"clicked",
			G_CALLBACK(on_IM_Button_Property_clicked),
			NULL);

	w = glade_xml_get_widget(xml_prefedit, "buttonIMSU");
	g_signal_connect(GTK_WIDGET(w),
			"clicked",
			G_CALLBACK(on_IM_Button_ShiftUp_clicked),
			NULL);

	w = glade_xml_get_widget(xml_prefedit, "buttonIMSD");
	g_signal_connect(GTK_WIDGET(w),
			"clicked",
			G_CALLBACK(on_IM_Button_ShiftDown_clicked),
			NULL);

	
	glade_xml_signal_connect(xml_prefedit, "on_noConvRadio_toggled",
			G_CALLBACK(on_noConvRadio_toggled));
	
	glade_xml_signal_connect(xml_prefedit, "on_tc2scRadio_toggled",
			G_CALLBACK(on_tc2scRadio_toggled));
	
	glade_xml_signal_connect(xml_prefedit, "on_sc2tcRadio_toggled",
			G_CALLBACK(on_sc2tcRadio_toggled));
	
	//zzc
	glade_xml_signal_connect(xml_prefedit, "on_inTrayRadio_toggled",
			G_CALLBACK(on_inTrayRadio_toggled));
	
	glade_xml_signal_connect(xml_prefedit, "on_notInTrayRadio_toggled",
			G_CALLBACK(on_notInTrayRadio_toggled));

	//zzc
	glade_xml_signal_connect(xml_prefedit, "on_fontPicker_font_set",
			G_CALLBACK(on_fontPicker_font_set));
	
	glade_xml_signal_connect(xml_prefedit, "on_fgColorPicker_color_set",
			G_CALLBACK(on_fgColorPicker_color_set));
	
	glade_xml_signal_connect(xml_prefedit, "on_bgColorPicker_color_set",
			G_CALLBACK(on_bgColorPicker_color_set));
	
	
	
	w = glade_xml_get_widget(xml_prefedit, "buttonSymbolAdd");
	g_signal_connect(GTK_BUTTON(w),
			"clicked",
			G_CALLBACK(on_Symbol_Button_Add_clicked),
			xml_prefedit);
	
	w = glade_xml_get_widget(xml_prefedit, "buttonSymbolDel");
	g_signal_connect(GTK_BUTTON(w),
			"clicked",
			G_CALLBACK(on_Symbol_Button_Del_clicked),
			xml_prefedit);

	w = glade_xml_get_widget(xml_prefedit, "buttonSymbolApply");
	g_signal_connect(GTK_BUTTON(w),
			"clicked",
			G_CALLBACK(on_Symbol_Button_Apply_clicked),
			NULL);
	
	w = glade_xml_get_widget(xml_prefedit, "buttonWordAdd");
	g_signal_connect(GTK_BUTTON(w),
			"clicked",
			G_CALLBACK(on_Word_Button_Add_clicked),
			NULL);

	w = glade_xml_get_widget(xml_prefedit, "buttonWordDel");
	g_signal_connect(GTK_BUTTON(w),
			"clicked",
			G_CALLBACK(on_Word_Button_Del_clicked),
			NULL);
	
	w = glade_xml_get_widget(xml_prefedit, "buttonWordApply");
	g_signal_connect(GTK_BUTTON(w),
			"clicked",
			G_CALLBACK(on_Word_Button_Apply_clicked),
			NULL);
	
	w = glade_xml_get_widget(xml_prefedit, "componentOption");
	g_signal_connect(G_OBJECT(GTK_OPTION_MENU(w)->menu), "deactivate",
			 G_CALLBACK(on_componentOption_selected), xml_prefedit);

	w = glade_xml_get_widget(xml_prefedit, "notebook");
	gtk_notebook_remove_page(GTK_NOTEBOOK(w),3);

	gconf_client_notify_add(client, STATUS_COMMAND_KEY,
			on_Status_Command_toggled,
			NULL, NULL, NULL);
			
	w = glade_xml_get_widget(xml_prefedit, "button10");
	g_signal_connect(GTK_BUTTON(w),
			"clicked",
			G_CALLBACK(on_help_button_clicked),
			NULL);
	
	w = glade_xml_get_widget(xml_prefedit, "button10");
	g_signal_connect(GTK_BUTTON(w),
			"clicked",
			G_CALLBACK(on_help_button_clicked),
			NULL);	
	
	gtk_main();
	
	return 0;
}

// vi:ts=4:sw=4:nowrap:cin:expandtab
